package com.hnevc.wechat;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    Fragment a,b,c,d;
    List<Fragment> fragmentList;
    ViewPager v1;
    ImageView ia,ib,ic,id;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        a=new BlankFragment();
        b=new BlankFragment1();
        c=new BlankFragment2();
        d=new BlankFragment3();

        ia= (ImageView) this.findViewById(R.id.ia);
        ib= (ImageView) this.findViewById(R.id.ib);
        ic= (ImageView) this.findViewById(R.id.ic);
        id= (ImageView) this.findViewById(R.id.id);

        fragmentList=new ArrayList<>();
        fragmentList.add(a);
        fragmentList.add(b);
        fragmentList.add(c);
        fragmentList.add(d);


        FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {

            public Fragment getItem(int position) {
                return fragmentList.get(position);
            }
            public int getCount() {
                return fragmentList.size();
            }

        };
        v1= (ViewPager) findViewById(R.id.vp);
        v1.setAdapter(adapter);
        ia.setSelected(true);
        v1.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {

                switch (position) {
                    case 0:
                        ia.setSelected(true);
                        ib.setSelected(false);
                        ic.setSelected(false);
                        id.setSelected(false);
                        break;
                    case 1:
                        ia.setSelected(false);
                        ib.setSelected(true);
                        ic.setSelected(false);
                        id.setSelected(false);
                        break;
                    case 2:
                        ia.setSelected(false);
                        ib.setSelected(false);
                        ic.setSelected(true);
                        id.setSelected(false);
                        break;
                    case 3:
                        ia.setSelected(false);
                        ib.setSelected(false);
                        ic.setSelected(false);
                        id.setSelected(true);
                        break;

                }
            }


            });

    }

    public void ba(View view) {
        v1.setCurrentItem(0);
    }
    public void bb(View view) {
        v1.setCurrentItem(1);
    }
    public void bc(View view) {
        v1.setCurrentItem(2);
    }
    public void bd(View view) {
        v1.setCurrentItem(3);
    }
}